package org.ch00.test09.demo03;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

/*
 *
 *@author XCH
 *@date 2025 - 03 - 10 - 19:59
 *
 */
public class MainTest {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        ExecutorService executor = Executors.newFixedThreadPool(10) ;

        Future<Long> future1 = executor.submit(new SumCallable(1, 100));
        Future<Long> future2 = executor.submit(new SumCallable(101, 900));
        Future<Long> future3 = executor.submit(new SumCallable(901, 1000));

        try {
            long totalSum = future1.get() + future2.get() + future3.get();
            System.out.println("结果: " + totalSum);
        } catch (InterruptedException | ExecutionException e) {
            throw new RuntimeException(e);
        }

        executor.shutdown();
    }
}
